import React from 'react';
import {inject, observer} from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { Form , RouteLayout , ListEditable } from 'weaver-mobile-page';
import { Icon, Result , Tools , Modal , Bubble} from 'weaver-mobile';
import { toJS } from 'mobx';
import MeetingUtil from '../../../util/meetingUtil';
const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;

const List = ListEditable.List

@inject('viewMeetingStore')
@withRouter
@observer
class SignCreate extends React.Component {
  constructor(props) {
      super(props);
      // this.state = {
      //   disabled:false,
      // };
    }

    componentWillMount(){
      this.setState({disabled:false})
      // if(this.props.location.pathname === '/calendar/detail/decisionData'){
      //   const { setState } = this.props.viewMeetingStore;
      //   setState({isView:'1',renderToDecision:false})
      // }
    }
    
    componentDidMount() {
      const { getSignCreateSet , setState ,meetingId} = this.props.viewMeetingStore;
      //考虑到刷新的时候
      let meetingIdTemp = meetingId?meetingId:sessionStorage.getItem('meetingId')
      //getSignCreateSet();
    }

    componentWillReceiveProps (nextProps) {
      // if(nextProps.location.pathname === '/calendar/detail/decisionData'){
      //   const { setState } = this.props.viewMeetingStore;
      //   setState({isView:'1'})
      // }
    }

    componentWillUnmount () {
      
    }

    getKey(f) {
      let key = "";
      if (f.domkey) key = f.domkey.join("__");
      return key;
    }

    getFields = ()=>{
      const { signCreateForm } = this.props.viewMeetingStore;
      const { isInit ,conditioninfo } = signCreateForm;
      const groups = [];
      isInit && conditioninfo.length!==0 && conditioninfo.forEach((group) => {
        const fields = [];
        group.items.forEach((field) => {
          if(this.getKey(field) == 'defaultAllowSignTime'){
            fields.push(
              <div className='signSet'>
                <div className='signFront'><span>{getLabel('514053','会议开始前')}</span></div>
                <Form.Item
                  key={this.getKey(field)}
                  form={signCreateForm}
                  fieldConfig={field}
                  onChange={signCreateForm.onChange}
                />
                <div className='signBehind'><span>{getLabel(514054,'分钟可以签到')}</span></div>
            </div>
            );
            fields.push(
                <div className='signSetRemark'>
                  <div className='signSetRemarkFont'>
                <span style={{'margin-left': '22px'}}>{getLabel('514150','输入0时，表示不限制签到时间。')}</span>
                </div>
                </div>
            );
          }else if(this.getKey(field) == 'afterSignCanBack' &&signCreateForm.formParams.allowSignBack == '1'){
            fields.push(
              <div className='signSet'>
                <div className='signFront'><span>{getLabel('383592','会议签到')}</span></div>
                <Form.Item
                  key={this.getKey(field)}
                  form={signCreateForm}
                  fieldConfig={field}
                  onChange={signCreateForm.onChange}
                />
                <div className='signBehind'><span>{getLabel(520923,'分钟后才能签退')}</span></div>
            </div>
            );
          }else if(this.getKey(field) == 'defaultAllowSignBackTime' &&signCreateForm.formParams.allowSignBack == '1'){
            fields.push(
              <div className='signSet'>
                <div className='signFront'><span>{getLabel('509652','会议结束')}</span></div>
                <Form.Item
                  key={this.getKey(field)}
                  form={signCreateForm}
                  fieldConfig={field}
                  onChange={signCreateForm.onChange}
                />
                <div className='signBehind'><span>{getLabel(509653,'分钟后不能签退')}</span></div>
            </div>
            );
            fields.push(
              <div className='signSetRemark'>
                <div className='signSetRemarkFont'>
              <span style={{'margin-left': '22px'}}>{getLabel('510318','输入0时，表示不限制签退时间。')}</span>
              </div>
              </div>
          );
          }else if(signCreateForm.formParams.allowSignBack == '1'|| this.getKey(field) == 'allowSignBack'){
            fields.push(
            <Form.Item
            key={this.getKey(field)}
            form={signCreateForm}
            fieldConfig={field}
            onChange={signCreateForm.onChange}
          />);
          }
        })
        groups.push(
          // 分组
          <div className='fold-group' key={group.title}>
            <div className={`${group.show ? 'show' : 'hide'}`}>
              {fields}
            </div>
          </div>
        )
      })
      return groups;
    }

    render() {
      return (
        <div className={'signcreate-data-contain'} >
          {this.getFields()}
        </div>
      )
    }
}

export default SignCreate;